package com.fs.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fs.pojo.Sup;
import com.fs.service.SupService;
import com.fs.util.ResponseDataUtil;
import com.fs.vo.Condition;
import com.fs.vo.ResponseData;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author hyy
 * @version 1.0
 * @description: 供应商管理控制层
 * @date 2024/10/14 16:17
 */
@RestController
@RequestMapping("/purchase/sup")
public class SupController {
    @Resource
    private SupService supService;

    /**
     * 分页查循信息
     * @param condition
     * @return
     */
    @PostMapping("/query")
    public ResponseData querySups(@RequestBody Condition<Sup> condition){
        //仓库分页查询信息
        Page<Sup> supPage = supService.querySups(condition.getPage(),condition.getCount(), (Sup) condition.getSearch());
        return supPage!=null? ResponseDataUtil.buildOk(supPage):ResponseDataUtil.buildFail(null);
    }

    /**
     * 通过Id查询供应商信息
     * @param  id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseData querySupById(@PathVariable Integer id){
        Sup whWarehousePage = supService.querySupByID(id);
        return whWarehousePage!=null?ResponseDataUtil.buildOk(whWarehousePage):ResponseDataUtil.buildFail(null);
    }

    /**
     * 删除供应商信息
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public ResponseData delSup(@PathVariable Integer id){
        Integer result = supService.delSUp(id);
        return result!=0?ResponseDataUtil.buildOk("200","删除成功"):ResponseDataUtil.buildFail(null);
    }

    /**
     * 新增供应商信息
     * @param sup
     * @return
     */
    @PostMapping
    public ResponseData addSup(@RequestBody Sup sup){
        Integer result = supService.addSup(sup);
        return result!=0?ResponseDataUtil.buildOk("200","新增成功"):ResponseDataUtil.buildFail(null);
    }

    /**
     * 修改供应商信息
     * @param sup
     * @return
     */
    @PostMapping("update")
    public ResponseData updateSup(@RequestBody Sup sup){
        Integer result = supService.updateSup(sup);
        return result!=0?ResponseDataUtil.buildOk("200","修改成功"):ResponseDataUtil.buildFail(null);
    }
}
